/**
  ******************************************************************************
  * @file    Project/STM32F10x_StdPeriph_Template/main.c 
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */  

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "./led/led.h"
#include "./usart/usart.h"
#include "sys.h"
#include "./i2c/i2c.h"
#include "OLED.h"

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
	delay_init();
	led_init();
	usart1_init(115200);
	i2c_init();
	OLED_Init();
	
	uint8_t command[50];
	int commandLength = 0;
	
	/* Infinite loop */
	while (1)
	{
		commandLength = Command_GetCommand(command);
		if (commandLength != 0)
		{
			send_buf(command, commandLength);
			
			for (int i = 2; i < commandLength - 1; i += 2)
			{
				uint8_t state = 1;
				if (command[i + 1] == 0x00)
				{
					state = 0;
				}
				if (command[i] == 0x01)
				{
					LED0(state);
				}
			}
		}
//		LED0(0);
////		printf("ON\r\n");
//		delay_ms(1000);
//		LED0(1);
////		printf("OFF\r\n");
//		delay_ms(15);	
	}
}






/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
